/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.thieunv.btvn1;

import java.util.Scanner;

/**
 *
 * @author Leo
 */
public class Bai2_Muc1_UCLN {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a,b;
        boolean cont = true;
        do{
            System.out.println("Nhap 2 so a va b: ");
            a = sc.nextLong();
            b = sc.nextLong();
            if(a<=0||b<=0)
                System.out.println("Nhap cac so nguyen duong\nNhap lai");
            else
                cont = false;
        }while(cont);
        System.out.println("Uoc chung lon nhat cua hai so " + a + " va " + b + " la " + greatestCommonDivisor(a,b));
    }
    
    public static long greatestCommonDivisor(long a, long b){
        while(a!=0&&b!=0){
            if(a>b)
                a %= b;
            else
                b %= a;
        }
        if(a==0)
            return b;
        else
            return a;
    }
}
